package o;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.CancellationSignal;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import androidx.core.content.res.FontResourcesParserCompat.a;
import androidx.core.content.res.FontResourcesParserCompat.e;
import androidx.core.provider.FontsContractCompat.b;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.util.List;

@RequiresApi(24)
@RestrictTo({d.ॱ})
class ga extends gb {
    private static final Constructor ˊ;
    private static final Class ˋ;
    private static final Method ˎ;
    private static final Method ˏ;

    ga() {
    }

    static {
        Method method;
        Constructor constructor;
        Class cls;
        Throwable e;
        Method method2 = null;
        try {
            Class cls2 = Class.forName("android.graphics.FontFamily");
            Constructor constructor2 = cls2.getConstructor(new Class[0]);
            Method method3 = cls2.getMethod("addFontWeightStyle", new Class[]{ByteBuffer.class, Integer.TYPE, List.class, Integer.TYPE, Boolean.TYPE});
            method = Typeface.class.getMethod("createFromFamiliesWithDefault", new Class[]{Array.newInstance(cls2, 1).getClass()});
            method2 = method3;
            constructor = constructor2;
            cls = cls2;
        } catch (ClassNotFoundException e2) {
            e = e2;
            Log.e("TypefaceCompatApi24Impl", e.getClass().getName(), e);
            method = null;
            constructor = null;
            cls = null;
            ˊ = constructor;
            ˋ = cls;
            ˏ = method2;
            ˎ = method;
        } catch (NoSuchMethodException e3) {
            e = e3;
            Log.e("TypefaceCompatApi24Impl", e.getClass().getName(), e);
            method = null;
            constructor = null;
            cls = null;
            ˊ = constructor;
            ˋ = cls;
            ˏ = method2;
            ˎ = method;
        }
        ˊ = constructor;
        ˋ = cls;
        ˏ = method2;
        ˎ = method;
    }

    public static boolean ˏ() {
        if (ˏ == null) {
            Log.w("TypefaceCompatApi24Impl", "Unable to collect necessary private methods.Fallback to legacy implementation.");
        }
        return ˏ != null;
    }

    private static Object ˎ() {
        try {
            return ˊ.newInstance(new Object[0]);
        } catch (IllegalAccessException e) {
            return null;
        } catch (InstantiationException e2) {
            return null;
        } catch (InvocationTargetException e3) {
            return null;
        }
    }

    private static boolean ॱ(Object obj, ByteBuffer byteBuffer, int i, int i2, boolean z) {
        try {
            return ((Boolean) ˏ.invoke(obj, new Object[]{byteBuffer, Integer.valueOf(i), null, Integer.valueOf(i2), Boolean.valueOf(z)})).booleanValue();
        } catch (IllegalAccessException e) {
            return false;
        } catch (InvocationTargetException e2) {
            return false;
        }
    }

    private static Typeface ॱ(Object obj) {
        try {
            Array.set(Array.newInstance(ˋ, 1), 0, obj);
            return (Typeface) ˎ.invoke(null, new Object[]{r0});
        } catch (IllegalAccessException e) {
        } catch (InvocationTargetException e2) {
        }
        return null;
    }

    @Nullable
    public Typeface ˋ(Context context, @Nullable CancellationSignal cancellationSignal, @NonNull b[] bVarArr, int i) {
        Object ˎ = ˎ();
        if (ˎ == null) {
            return null;
        }
        dy dyVar = new dy();
        for (b bVar : bVarArr) {
            Uri ˊ = bVar.ˊ();
            ByteBuffer byteBuffer = (ByteBuffer) dyVar.get(ˊ);
            if (byteBuffer == null) {
                byteBuffer = gh.ˋ(context, cancellationSignal, ˊ);
                dyVar.put(ˊ, byteBuffer);
            }
            if (byteBuffer == null) {
                return null;
            }
            if (!ॱ(ˎ, byteBuffer, bVar.ˎ(), bVar.ˏ(), bVar.ˋ())) {
                return null;
            }
        }
        Typeface ॱ = ॱ(ˎ);
        if (ॱ == null) {
            return null;
        }
        return Typeface.create(ॱ, i);
    }

    @Nullable
    public Typeface ॱ(Context context, e eVar, Resources resources, int i) {
        Object ˎ = ˎ();
        if (ˎ == null) {
            return null;
        }
        for (a aVar : eVar.ˊ()) {
            ByteBuffer ˏ = gh.ˏ(context, resources, aVar.ʼ());
            if (ˏ == null || !ॱ(ˎ, ˏ, aVar.ˎ(), aVar.ॱ(), aVar.ˏ())) {
                return null;
            }
        }
        return ॱ(ˎ);
    }
}
